<template>
  <!-- 工程基本情况 -->

  <a-form-model ref="ruleForm" :model="projectVO" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
    <a-spin :spinning="loading" class="form-item">
      <!-- 表单 -->

      <title-name title="工程基本情况"></title-name>
      <custom-form :isEmit="false" :formList="formList" :form="projectVO" :editModel="editModel == 0 ? '' : ''"> </custom-form>

      <title-name title="资源配置情况"></title-name>
      <s-table
        bordered
        ref="table"
        :page-keys="['pageNum', 'pageSize']"
        tableLayout="fixed"
        size="default"
        rowKey="code"
        :columns="columns"
        :data="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        :showPagination="false"
      >
      </s-table>
      <custom-form class="mt12" :isEmit="false" :formList="formListFooter" :form="projectVO" :editModel="editModel == 0 ? '' : ''"> </custom-form>
      <!-- 页脚操作栏 -->
      <div class="btn_box tool-btns--fixed" style="bottom: 50px" v-if="editModel != 0">
        <a-button type="primary" :loading="loadingBtn.DRAFT" @click="next">下一步</a-button>
      </div>
    </a-spin>
  </a-form-model>
</template>

<script>
import { api } from '@/api/project/performanceAnalysis'
import BaseEditPage from '@/views/baseEditPage' // 编辑详情页基础配置
import BSelect from '@/components/BComponents/BSelect'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 分公司
// import { projectInfoColumns } from '../model.js'
import Moment from 'moment'

export default {
  name: 'projectInfo',
  extends: new BaseEditPage(),
  components: {
    SelectProject,
    BSelect,
    SelectSubCompany
  },

  data() {
    let that = this
    const columns = [
      {
        title: '',
        dataIndex: 'title'
      },
      {
        title: '备案项目经理',
        dataIndex: 'BAManager',
        customRender: (text, row, index) => {
          let disabled = that.$route.query.detailUrl || that.editModel == 0
          // return <BaseInput v-model={row.BAManager}></BaseInput>
          let obj = {
            children: text,
            attrs: {}
          }
          if (index == 5) {
            obj.attrs.colSpan = 2
          }
          if (index > 1 && index < 5 && this.form.projectVO.projectRecordManager) {
            obj.children = <BaseInput disabled={disabled} v-model={row.BAManager}></BaseInput>
          }else if(index == 1 && this.form.projectVO.projectRecordManager){
            obj.children = <BaseInputNumber min={0} max={1000} disabled={disabled} v-model={row.BAManager}></BaseInputNumber>
          }

          return obj
        }
      },
      {
        title: '实际项目经理',
        dataIndex: 'SJManager',
        customRender: (text, row, index) => {
          console.log(index,text)
          let disabled = that.$route.query.detailUrl || that.editModel == 0
          let obj = {
            children: text,
            attrs: {}
          }
          if (index == 5) {
            obj.attrs.colSpan = 0
          }
          if (index > 1 && index < 5 && this.form.projectVO.projectManager) {
            obj.children = <BaseInput  disabled={disabled} v-model={row.SJManager}></BaseInput>
          }else if(index == 1 && this.form.projectVO.projectManager){
            obj.children = <BaseInputNumber min={0} max={1000} disabled={disabled} v-model={row.SJManager}></BaseInputNumber>
          }
          return obj
        }
      }
    ]

    return {
      columns,
      loading: false, // 加载控件
      editModel: 1, // 操作状态:0 查看;1 编辑
      // form: { keyProgram: '', month: '', detailsList: [] }, // 表单
      id: '',
      selectedRowKeys: [],
      loadingBtn: {
        DELETE: false,
        DRAFT: false,
        SUBMITTED: false,
        REJECTED: false
      },

      projectVO: { detailsList: [] },
      loadData: () => {
        if (this.projectVO.detailsList.length > 0) {
          return new Promise((resolve, reject) => {
            resolve({
              data: this.projectVO.detailsList || []
            })
          })
        }
      },
      // rules: { month: [{ required: true, message: '请选择' }] }, // 校验规则
      init: false // 初始化控件
    }
  },
  props: {
    isAudit: {
      // 是否作为审批详情
      type: Boolean,
      default: false
    },
    form: {
      type: Object,
      default: {
        projectVO: {}
      }
    }
  },
  watch: {
    isAudit: {
      immediate: true,
      handler(val) {
        if (val) {
          this.$nextTick(() => {
            this.editModel = 0
          })
        }
      }
    },
    form: {
      handler(val) {
        this.projectVO = this.form.projectVO
        if(this.editModel*1===1){  //编辑用当前时间，当前人
          this.projectVO.modifiedTime = Moment(new Date()).format('YYYY-MM-DD')
          this.projectVO.creatorName = this.$userInfo().name
        }
        console.log(this.projectVO)
        this.projectVO.detailsList = [
          {
            title: '姓名',
            BAManager: this.projectVO.projectRecordManager?.name,
            SJManager: this.projectVO.projectManager?.name
          },
          {
            title: '年龄',
            BAManager: this.projectVO.projectRecordManager?.age,
            SJManager: this.projectVO.projectManager?.age
          },
          {
            title: '工作年限',
            BAManager: this.projectVO.projectRecordManager?.workNum,
            SJManager: this.projectVO.projectManager?.workNum
          },
          {
            title: '任项目经理年限',
            BAManager: this.projectVO.projectRecordManager?.managerNum,
            SJManager: this.projectVO.projectManager?.managerNum
          },
          {
            title: '执业资格',
            BAManager: this.projectVO.projectRecordManager?.workRigs,
            SJManager: this.projectVO.projectManager?.workRigs
          },
          {
            title: '备案项目经理是否到岗',
            BAManager: this.projectVO.projectRecordManager?.workIn,
            SJManager: this.projectVO.projectManager?.workIn
          }
        ]
        this.$refs.table.refresh(true)
      }
    }
  },
  computed: {
    formList() {
      return [
        {
          keyName: 'month',
          type: 'BaseInput',
          disabled: true,
          label: '月份'
        },
        // {
        //   keyName: 'branchCompanyName',
        //   type: 'BaseInput',
        //   disabled: true,
        //   label: '分公司'
        // },
        // {
        //   keyName: 'projectName',
        //   type: 'BaseInput',
        //   disabled: true,
        //   label: '项目名称'
        // },
        {
            keyName: 'projectId',
            type: 'orgTree',
            disabled: true,
            label: '所属单位',
            isNeedAuth: true,
            span: 16
        },
        {
          keyName: 'contractModelName',
          type: 'BaseInput',
          disabled: true,
          label: '工程承包模式'
        },
        {
          keyName: 'projectTypeName',
          type: 'BaseInput',
          disabled: true,
          label: '项目类型'
        },
        {
          keyName: 'projectFormats',
          type: 'BaseInput',
          disabled: true,
          label: '项目业态'
        },
        {
          keyName: 'projectImportanceName',
          type: 'BaseInput',
          disabled: true,
          label: '项目重要程度'
        },
        {
          keyName: 'keyProject',
          type: 'BaseInput',
          disabled: true,
          label: '是否为重点项目'
        },
        {
          keyName: 'totalKmArea',
          type: 'BaseInput',
          disabled: true,
          label: this?.projectVO?.linearIs ? '在施工程里程km' : '在建建筑面积万m²'
        },
        {
          keyName: 'contractAmount',
          type: 'BaseInput',
          disabled: true,
          label: '合同额（万元）'
        },
        {
          keyName: 'progress',
          type: 'BaseInput',
          disabled: true,
          label: '形象进度'
        },
        {
          keyName: 'creatorName',
          type: 'BaseInput',
          disabled: true,
          label: '创建人'
        },
        {
          keyName: 'modifiedTime',
          type: 'BaseInput',
          disabled: true,
          label: '创建时间'
        }
      ]
    },
    formListFooter() {
      return [
        {
          keyName: 'projectTotal',
          type: 'BaseInput',
          disabled: true,
          label: '项目总人数'
        },
        {
          keyName: 'allocatTotal',
          type: 'BaseInput',
          disabled: true,
          label: '配置人数情况'
        }
      ]
    }
  },
  mounted() {
    // 不为添加时请求详情

    if (this.editModel != 2) {
      // this.getDetailData()
    } else {
      this.$nextTick(() => {
        // 默认映射联系人为登陆人
        this.getMonth()
        this.getTable()
        this.init = true
      })
    }
  },

  methods: {
    next() {
      this.$emit('nextStep')
    },

  }
}
</script>
<style lang="less" scoped>
/deep/ .form-item  {
  .ant-input:not([disabled]),
  .ant-select:not(.ant-select-disabled) .ant-select-selection,
  .ant-calendar-picker-input,
  .ant-input-number:not([disabled]),
  .ant-cascader-picker {
    border-color: #e4ac0b;

    background-color: #fff9e8;
  }
  .ant-input-disabled,
  .ant-input-number-disabled .ant-input-number-input,
  .ant-time-picker-input[disabled] {
    border-color: #d9d9d9 !important;
    background-color: #f5f5f5 !important;
  }

  .remark {
    .ant-input {
      border-color: inherit;
      background-color: initial;
    }
  }
}
</style>
